package cn.rick.service.impl;

import cn.rick.entity.SysDictType;
import cn.rick.mapper.SysDictTypeMapper;
import cn.rick.service.ISysDictTypeService;
import cn.rick.util.LocalDateTimeUtil;
import cn.rick.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 字典类型表 服务实现类
 * </p>
 *
 * @author house_store
 * @since 2022-10-19 14:39:46
 */
@Service
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService {

    @Override
    public List<SysDictType> selectAllByParam(SysDictType param, String startDate, String endDate) {
        LambdaQueryWrapper<SysDictType> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.orderByDesc(SysDictType::getCreateTime);

        //模糊查询字典名称
        if (StringUtils.isNotEmpty(param.getDictName())) {
            queryWrapper.like(SysDictType::getDictName, param.getDictName());
        }
        //模糊查询字典类型
        if (StringUtils.isNotEmpty(param.getDictType())) {
            queryWrapper.like(SysDictType::getDictType, param.getDictType());
        }
        //查询字典状态
        if (StringUtils.isNotEmpty(param.getStatus())) {
            queryWrapper.eq(SysDictType::getStatus, param.getStatus());
        }
        //查询创建时间区间
        if (StringUtils.isNotEmpty(startDate) && StringUtils.isNotEmpty(endDate)) {
            LocalDateTime start = LocalDateTimeUtil.stringToLocalDateTime(startDate + " 00:00:00");
            LocalDateTime end = LocalDateTimeUtil.stringToLocalDateTime(endDate + " 23:59:59");
            queryWrapper.between(SysDictType::getCreateTime, start, end);
        }

        return baseMapper.selectList(queryWrapper);
    }
}
